package com.linsir.lin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linsir.core.BaseResponse;
import com.linsir.core.CodeEnum;
import com.linsir.lin.mapper.PositionOrganMapper;
import com.linsir.lin.pojo.PositionOrgan;
import com.linsir.lin.service.PositionOrganService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;

/**
 * @author ：huangqg
 * @date ：Created in 2021/7/15 10:00
 * @description：接口实现类
 * @modified By：
 * @version: 1.0.0
 */
@Service
@Slf4j
public class PositionOrganServiceImpl extends ServiceImpl<PositionOrganMapper, PositionOrgan> implements IService<PositionOrgan>, PositionOrganService {
    /**
     * 根据机构ID获取职务列表
     * @param organId
     * @return
     */
    @Override
    public List<PositionOrgan> positionOrganList(Integer organId){
        QueryWrapper<PositionOrgan> queryWrapper=new QueryWrapper<PositionOrgan>();
        queryWrapper.eq("organ_id",organId);
        List<PositionOrgan> positionOrganList=list(queryWrapper);
        return positionOrganList;
    }

    /**
     * 增加组织结构与职务关系
     * @param positionOrgan
     * @return
     * @throws ParseException
     */
    @Override
    public BaseResponse<Boolean> addOrUpdate(PositionOrgan positionOrgan)throws ParseException{
        boolean data = saveOrUpdate(positionOrgan);
        if (data)
        {
            return new BaseResponse<Boolean>(CodeEnum.SUCCESS,"增加组织结构与职务关系成功",data);
        }
        else
        {
            return new BaseResponse<Boolean>(CodeEnum.FAILED,"增加组织结构与职务关系失败",data);
        }
    }

    /**
     * 根据职务ID获取职务与组织关系实体
     * @param poistionId
     * @return
     */
    @Override
    public PositionOrgan getByPositionId(Integer poistionId){
        QueryWrapper<PositionOrgan> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("position_id",poistionId);
        return getOne(queryWrapper);
    }
}
